<template>
  <div class="wrapper">
    <swiper :options="swiperOption" v-if="showSwiper">
      <!-- slides -->
      <swiper-slide v-for="item of list" :key="item.id">
          <img class="swiper-img" :src="item.imgUrl" style="height: 127px;"/>
      </swiper-slide>
      <!-- 分页功能，图片下方的小点 -->
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default{
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        // 分页小点属性
        pagination: '.swiper-pagination',
        loop: true // 循环轮播
      }
    }
  },
  computed: {
    showSwiper () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped>
  // 样式穿透 让wrapper组件下的所有.swiper-pagination-bullet遵循下面的样式
  .wrapper >>> .swiper-pagination-bullet-active
    background: #fff
  .wrapper
    // 实现图片的自适应
    overflow: hidden
    width: 100%
    height: 0
    padding-bottom: 31.25%
    .swiper-img
      width: 100%
</style>
